<template>
  <div class="searchIndex">
    <div class="sear">
      <form @submit="searching">
        <i></i>
        <input
          type="text"
          v-model="keywords"
          @input="inputing"
          placeholder="请输入歌手、歌曲"
        />
      </form>
      <button @click="back">取消</button>
    </div>
    <component
      :is="componentName"
      :keywords="keywords"
      @play="$emit('play', $event)"
      @searchindex="searchChange"
    ></component>
  </div>
</template>
<script>
import HotSearch from "@/components/HotSearch";
import SearchSuggest from "@/components/SearchSuggest";
import SearchResult from "@/components/SearchResult";
export default {
  name: "SearchIndex",
  data() {
    return {
      componentName: "hotSearch",
      keywords: "",
    };
  },
  created() {},
  methods: {
    inputing(e) {
      if (e.target.value == "") {
        this.componentName = "HotSearch";
      } else {
        this.componentName = "SearchSuggest";
      }
    },
    searching() {
      this.componentName = "SearchResult";
    },
    searchChange(e) {
      // console.log(e);
      this.keywords = e;
      this.componentName = "SearchResult";
    },
    back(){
      this.$router.go(-1)
    }
  },
  components: {
    HotSearch,
    SearchSuggest,
    SearchResult,
  },
};
</script>
<style lang="less" scoped>
.searchIndex {
  .sear {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    form {
      padding: 15px 10px;
      position: relative;
      flex: 1;
      i {
        width: 13px;
        height: 13px;
        background-image: url();
        position: absolute;
        left: 12px;
        top: 24px;
        margin: 0 8px;
        z-index: 3;
      }
      input {
        position: relative;
        width: 100%;
        height: 30px;
        padding: 0 30px;
        box-sizing: border-box;
        background: #ebecec;
        border-radius: 30px;
      }
    }
    button {
      border: 0;
      color: #333;
      width: 50px;
      height: 30px;
      margin-right: 10px;
      background: #ebecec;
    }
  }
}
</style>